<template>
  <CompOperate
      :field="field"
      :designer="designer"
      :design-state="designState"
      :parent-list="parentList"
      :parent-widget="parentWidget"
      :sub-form-row-id="subFormRowId"
      :sub-form-row-index="subFormRowIndex"
      :sub-form-col-index="subFormColIndex"
      :index-of-parent-list="indexOfParentList"
      :display-style="field.options.displayStyle"
  >
    <div class="scene-window-widget" :style="getStyle('area')">
      <div class="window-area">
        <div class="replenish" v-if="optionsInfo['replenishShown']">
          <ScrollX>{{ optionsInfo.replenishContent }}</ScrollX>
        </div>
        <div class="window-info flex-box">
          <div class="flex-box-left flex-item" :style="getStyle('number')" v-if="optionsInfo['roomNumberShown']">
            <template v-if="roomNumberAutoInfo">
              {{optionsInfo['roomNumberAuto'] ? getWindowDeptInfo['roomNo'] : optionsInfo['roomNumber'] }}
            </template>
          </div>
          <div class="flex-box-right flex-item" :style="getStyle('room')"
               :class="{'inside-prior-info': optionsInfo['priorInfo']}">
            <template v-if="optionsInfo['businessContentAuto']">
              <div class="inside" v-html="getRoomInfo"/>
              <div class="prior-info" v-if="optionsInfo['priorInfo']">{{ optionsInfo['priorName'] }}</div>
            </template>
            <template v-else>
              <div class="inside registerObjName" :style="getStyle('registerObjName')" v-html="getWinInfo('registerObjName')"/>
            </template>

          </div>
        </div>
      </div>
    </div>
  </CompOperate>
</template>

<script>
import emitter from "@/utils/designer/emitter";
import {pxToVw} from '@/utils/common';
import ScrollX from '@c/public/seamlessScroll/ScrollX.vue';
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import {buildParentApi} from "@/utils/designer/util";

export default {
  name: "scene-window-1920-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  components: {
    CompOperate,
    ScrollX
  },

  props: {
    widget: Object,
    devType: {
      type: Boolean,
      default: false,
    },
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    designer: Object,
    designState: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */ type: String,
      default: "",
    },
    headTitle: {
      type: String,
      default: "",
    },
    visibleTitle: {
      type: Boolean,
    },
    //prop传入的表单JSON配置
    parentApi: {
      type: Object,
      default: () => buildParentApi()
    },
  },

  data() {
    return {
      optionsInfo: Object(),
      header: require("@a/images/design/header.jpeg"),
      pause: require("@a/images/design/pause.png"),
    }
  },

  computed: {
    // 设置的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Array();
        let Obj = Object();
        switch (val) {
          case 'area':
            let {topBottom = 28, rightLeft = 30} = info?.padding
            Reflect.set(Obj, 'height', pxToVw(info.areaHeight));
            Reflect.set(Obj, 'paddingTop', pxToVw(topBottom));
            Reflect.set(Obj, 'paddingBottom', pxToVw(topBottom));
            Reflect.set(Obj, 'paddingLeft', pxToVw(rightLeft));
            Reflect.set(Obj, 'paddingRight', pxToVw(rightLeft));
            return Obj;
          case 'room':
            Reflect.set(Obj, 'fontSize', pxToVw(info.roomNameFontSize));
            Reflect.set(Obj, 'color', (info.roomNameColor));
            Reflect.set(Obj, 'background', (info.roomNameBackground));
            Reflect.set(Obj, 'fontWeight', (info.roomNameFontWeight));
            return Obj;
          case 'number':
            Reflect.set(Obj, 'fontSize', pxToVw(info.roomNumberFontSize));
            Reflect.set(Obj, 'background', (info.roomNumberBackground));
            return Obj;
          case 'registerObjName':
            Reflect.set(Obj, 'fontSize', pxToVw(info?.registerObjNameFontSize));
            Reflect.set(Obj, 'color', '#FFFFFF');
            return Obj;
        }
      }
    },

    roomNumberAutoInfo(){
      let info = (this.optionsInfo);
      return Reflect.has(info,'roomNumberAuto')
    },

    // 获取科室信息
    getWindowDeptInfo() {
      let devType = (this.devType);
      let roomDoctorInfo = this.$store.getters['getWindowDeptInfoInfo'];
      if (devType) {
        return roomDoctorInfo.apiData;
      } else {
        return roomDoctorInfo.mockData;
      }
    },


    getWinInfo() {
      return function (type) {
        let winInfo = (this.getWindowDeptInfo);
        return winInfo[type]
      }
    },

    getRoomInfo() {
      const self = this;
      let info = (self.optionsInfo) || Array();
      let deptInfo = (this.getWindowDeptInfo);
      if (info['roomNameAuto']) {
        if (!!info && !!info['roomNameKey']) {
          return deptInfo[info['roomNameKey']] || deptInfo['roomName']
        } else {
          return deptInfo['roomName']
        }
      } else {
        return info['roomName']
      }
    }
  },

  created() {
    this.registerToRefList();
    this.initEventHandler();
    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
  },

  methods: {
    // 接收父组件传递过来的数据
    executeMethod(key, data) {
      switch (key) {
        case "roomDoctorInfo":
          console.log(`医生-患者-信息-${data}`);
          this.$store.dispatch('setRoomDoctorInfo', this.$lodash.cloneDeep(data))
          break
        case "roomDeptInfo":
          console.log(`科室诊室信息-${data}`)
          this.$store.dispatch('setWindowDeptInfo', this.$lodash.cloneDeep(data))
          break
      }
    },
  },


  watch: {
    field: {
      handler: function (val) {
        let optionsInfo = (val.options[val.options.config]);
        if (!(Reflect.has(optionsInfo, 'roomNumberShown'))) {
          Reflect.set(optionsInfo, 'roomNumberShown', true);
        }
        this.optionsInfo = optionsInfo;
      },
      deep: true,
      immediate: true
    }
  },

  destroyed() {
    this.unregisterFromRefList();
  },

};
</script>

<style lang="scss" scoped>
.scene-window-widget {
  color: #333;
  height: 150px;
  font-size: 40px;
  padding: 28px 30px;
  box-sizing: border-box;
  flex: inherit;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;


  .window-area {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: transparent;

    .replenish {
      width: 100%;
      height: 112px;
      font-size: 80px;
      color: #0059B3;
      line-height: 112px;
      text-align: center;
      font-style: normal;
      @include fontWeight()
    }

    .window-info {
      border-radius: 12px;
      overflow: hidden;
      box-shadow: 30px 30px 30px -10px rgba(0, 0, 0, 0.15),
      inset 15px 15px 10px rgba(255, 255, 255, 0.75),
      -15px -15px 35px rgba(255, 255, 255, 0.55),
      inset -1px -1px 10px rgba(0, 0, 0, 0.2);

      .flex-item {
        overflow: hidden;
        color: #FFFFFF;
        display: flex;
        text-align: center;
        align-items: center;
        justify-content: center;
        border: none;
      }

      .flex-box-left {
        flex-basis: 26%;
        font-size: 460px;
        font-weight: bolder;
        @include fontWeight();
        background: rgba(0, 80, 161, 1);
      }

      // 高度--单行
      .flex-box-right {
        flex-basis: 74%;
        font-size: 280px;
        background: rgba(0, 89, 179, 1);
        display: flex;
        align-items: center;
        padding: 0 20px;
        justify-content: center;

        .inside {
          height: 100%;
          line-height: 1.4;
          display: flex;
          align-self: center;
          align-items: center;
          white-space: nowrap;
          justify-content: center;
        }

        .registerObjName{
          white-space: inherit;
        }

      }

      // 高度--优先行
      .inside-prior-info {
        display: flex;
        flex-direction: column;
        line-height: 1.2;

        .inside {
          height: auto;
          line-height: inherit;
        }

        .prior-info {
          font-size: 200px;
        }
      }
    }
  }
}
</style>